## traditional MM Likert outcome using only black respondents
##
## August 5, 2019
##
## Kevin Quinn
## University of Michigan
##

library(MCMCpack)
set.seed(810411)

mydata <- read.csv("../ScaleRaceSpring2017clean.csv")

## subset data
mydata <- mydata[mydata$R.race == "Black",]
mydata <- mydata[!is.na(mydata$R.race),]



## keep responses and photo IDs but nothing else
inds <- 1:24
keep.vars <- c(paste("X", inds, "_Q339", sep=""),
               paste("X", inds, "a.id", sep=""))

mydata.sub <- mydata[, keep.vars]


## reshape into long format
mydata.sub.long <- reshape(mydata.sub, direction="long",
                           varying=list(c(1:24), c(25:48)),
                           v.names=c("Y", "photoID"),
                           ids=rownames(mydata.sub))

## keep only obs with non-missing values for MM
mydata.sub.long <- na.omit(mydata.sub.long)

mydata.sub.long <- mydata.sub.long[sample(1:nrow(mydata.sub.long),
                                          size=1000, replace=FALSE),]

cat("\n\nN =", nrow(mydata.sub.long), "\n\n") 


a3.M1.out <- MCMCoprobit(Y ~ as.factor(photoID), data=mydata.sub.long,
                         burnin=50000, mcmc=1000000, thin=50, tune=0.05,
                         verbose=10000, seed=71948
                         )


save(a3.M1.out, file="MM3.2.a3.M1.out.Rda")
